package components.photo
{
	import SEApp.components.se_source;
	
	import UIFree.ObjectEvent;
	import UIFree.controls.base.uif_source;
	import UIFree.controls.uif_close;
	import UIFree.uif_Timer;
	import UIFree.uif_component;
	import UIFree.uif_transition;
	
	import classes.clt_events;
	
	import components.clt_component;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	public class clt_curUserAvatar extends clt_component {
		private var _source: se_source;
		public function clt_curUserAvatar(parent: uif_component) {
			super(parent, -10, -10, 80, 80);
			var inner: Rectangle = getInner();
			_source = new se_source(this, inner.x, inner.y, inner.width, inner.height, app.styles.curUserAvatar);
			
			addEvent(Event.COMPLETE, doLoad, _source.source.contentLoaderInfo);
			addEvent(MouseEvent.CLICK, doClick, _source);
			
			new uif_close(this);
			setVisibility(false);
		}
		
		override protected function listenEvents():void {
			super.listenEvents();
			addEvent(clt_events.USERUPDATE, doUserUpdate, clt.workspace);
			addEvent(Event.CLOSE, doClose);
		}
		
		private function doUserUpdate(e: Event): void {
			_source.loadSource(clt.user.pic_small);
		}
		
		private function doLoad(e:Event):void {
			uif_Timer.one(5000, function(e: Event): void {
				var inner: Rectangle = parentComponent.getInner();
				slideShow();
				fx('x', x, inner.right - width, uif_transition.easeOut(uif_transition.Bounce, 3), 16, 4000).start();
				addEvent(clt_events.LOADPHOTOCOMPLETE, doPhotoLoad, clt.workspace);
			});
		}
		
		private function doClose(e: Event): void {
			slideHide(dispose);
		}
		
		private function doClick(e: Event): void {
			var imageURL: String = clt.user.pic_big;
			if (!_source.source.bitmapContentAccess)
				imageURL = clt_servers.GETIMAGEURL + imageURL;
			
			clt.workspace.loadPhoto(imageURL);
		}
		
		private function doPhotoLoad(e: Event): void {
			slideHide(dispose);
		}
	}
}